package com.example.zhongxiangmo;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.pm.PermissionInfo;
import android.media.DrmInitData;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

import java.util.Timer;
import java.util.TimerTask;

public class MainActivity extends AppCompatActivity {

    int i = 6;
    @SuppressLint("HandlerLeak")
    Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            i--;
            if ( i>= 1){
                mTvYindao.setText(i+"");
            }else {
                timer.cancel();
                Intent intent = new Intent(MainActivity.this, HomeActivity.class);

                startActivity(intent);
            }
        }
    };
    private TextView mTvYindao;
    private Timer timer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        mTvYindao = (TextView) findViewById(R.id.tv_yindao);
        initData();
    }

    private void initData() {
        TimerTask timerTask = new TimerTask() {
            @Override
            public void run() {

                handler.sendEmptyMessage(1);
            }
        };
        timer = new Timer();
        timer.schedule(timerTask,0,1000);
    }
}
